<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class UsercenterController extends CommonController{

	//构造函数
	public function __init()
	{
		parent::__init();
	}
	
    //动作
    public function orderList(){
    	$orderModel=new \Common\Model\gorder;
       $data=$orderModel->where('user_uid',$_SESSION['id'])->get();
//	   var_dump($data);die;
	   View::with('data',$data);
	   View::make();
    }




	public function information(){
		$uid=$_GET['uid'];
		$InforModel=new \Common\Model\user;	
		if(IS_POST){			
//			var_dump($_POST);die;			
			$result=$InforModel->store();
			if(!$result){
				View::error($InforMode->getError());
			}
			View::success('保存成功！',U('Home/Usercenter/information',array('uid'=>$uid)));
		}
		
		$userData=$InforModel->where('uid',$uid)->find();
		$userData['address']=explode(',', $userData['address']);
//		var_dump($userData);die;
		View::with('userData',$userData);
		View::make();
	}
	
	public function address(){
		$uid=$_GET['uid'];
//		var_dump($uid);die;
		$addressModel=new \Common\Model\user_address;	
		if(IS_POST){
//			var_dump($_POST);die;
			$uid=$_POST['uid'];
			$result=$addressModel->store();
			if(!$result){
				View::error($addressModel->getError());
			}	
			View::success('保存成功！',U('Home/Usercenter/address',array('uid'=>$uid)));
		}
		
		$addressData=$addressModel->where('user_uid',$uid)->get();
//		$userData['address']=explode(',', $userData['address']);
//		var_dump($userData);die;
		View::with('addressData',$addressData);
		View::make();
	}
	
	
	public function getCommon(){
//		var_dump($_GET) ;
		$uid=$_GET['uid'];
		$uaid=$_GET['uaid'];
		$addressModel=new \Common\Model\user_address;	
		$no=array(
			'common'=>'no' 
		);
		$yes=array(
			'common'=>'yes' 
		);
		$addressModel->where('user_uid',$uid)->update($no);
		$addressModel->where('user_uid',$uid)->where('uaid',$uaid)->update($yes);
		
		View::ajax();die;
	}
	
}